package net.oschina.app.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.adapter.BaseRecyclerViewAdapter;
import net.oschina.app.bean.Friend;
import net.oschina.app.ui.view.CircleImageView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static net.oschina.app.util.UIUtils.getContext;

/**
 * Created by Administrator on 2017/4/6.
 * ?
 */

public class MessageFenSAdapter extends BaseRecyclerViewAdapter {
    private List<Friend> mList;
    public MessageFenSAdapter(Context context, List<Friend> list) {
        super(context);
        mList = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.user_info_item, null);
        MessageHolder messageHolder = new MessageHolder(view);
        return messageHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

        MessageHolder holder1 = (MessageHolder) holder;
        Friend friend = mList.get(position);
        holder1.mUserName.setText(friend.getName());
        if(friend.getGender() == 1 ){
            holder1.mUserSex.setImageResource(R.drawable.userinfo_icon_male);
        }else {
            holder1.mUserSex.setImageResource(R.drawable.userinfo_icon_female);
        }
        holder1.mUserAddress.setText(friend.getFrom());
        holder1.mUserWork.setText(friend.getExpertise());
        Glide.with(getContext()).load(friend.getPortrait()).into(holder1.mUserFace);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class MessageHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.user_face)
        CircleImageView mUserFace;
        @BindView(R.id.user_name)
        TextView mUserName;
        @BindView(R.id.user_address)
        TextView mUserAddress;
        @BindView(R.id.user_work)
        TextView mUserWork;
        @BindView(R.id.user_sex)
        ImageView mUserSex;
        public MessageHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
